package com.ctrip.ibu.permissions.security.controller;

import com.ctrip.ibu.permissions.common.api.ResponseData;
import com.ctrip.ibu.permissions.security.entity.User;
import com.ctrip.ibu.permissions.security.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * description
 *
 * @author r.shi 2020/03/30 21:15
 */
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("/list")
    public ResponseData<List<User>> list(@RequestBody User user) {
        return  ResponseData.success(userService.list(user));
    }

    @PostMapping("/create")
    public ResponseData<User> create(@RequestBody User user)  {
        return  ResponseData.success(userService.create(user));
    }

    @PutMapping("/update")
    public ResponseData<User> update(@RequestBody User user)  {
        return  ResponseData.success(userService.update(user));
    }

    @DeleteMapping("/delete")
    public ResponseData<User> delete(@RequestBody User user)  {
        userService.delete(user);
        return  ResponseData.success();
    }

}
